<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const obj = {
            name: "pink",
            age: 18,
            fn: function () {
                alert('你好')
            }
        };
        // 将复杂数据类型转换成JS0N字符串
        localStorage.setItem("obj", JSON.stringify(obj));
        // 将JSON字符串转化为对象来使用
        console.log(JSON.parse(localStorage.getItem("obj")));   
    </script>
</body>

</html>